
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:1、构造一副扑克牌
 */

class Card{
    private int rank;
    private String suit;

    public Card(int rank, String suit) {
        this.rank = rank;
        this.suit = suit;
    }

    public int getRank() {
        return rank;
    }

    public void setRank(int rank) {
        this.rank = rank;
    }

    public String getSuit() {
        return suit;
    }

    public void setSuit(String suit) {
        this.suit = suit;
    }

    @Override
    public String toString() {
        return "[ " + this.suit +" : " + this.rank + " ]";
    }
}



public class TestDemo {
    private static final String[] suits = {"♠","♥","♣","♦"};

    //新牌
    public static List<Card> buyCard() {
        ArrayList<Card> cards = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            for (int j = 1; j < 14; j++) {
                Card card = new Card(j, suits[i]);
                cards.add(card);
                //cards.add(new Card(j,suits[i]));
            }
        }
        return cards;
    }

    //交换牌
    private static void swap(List<Card> cards, int i, int j){
        Card tmp = cards.get(i);
        cards.set(i, cards.get(j));
        cards.set(j,tmp);
    }

    //洗牌
    public static void shuffle(List<Card> cards){
        int size = cards.size();
        for (int i = size-1; i > 0; i--) {
            Random random = new Random();
            int rand = random.nextInt(i);
            swap(cards,i,rand);
        }
    }

    public static void main(String[] args) {
        List<Card> cards = buyCard();
        System.out.println("买牌" + cards);
        shuffle(cards);
        System.out.println("洗牌"+cards);

        //3个人轮流揭5张牌
        List<List<Card>> list = new ArrayList<>();
        List<Card> list1 = new ArrayList<>();
        List<Card> list2 = new ArrayList<>();
        List<Card> list3 = new ArrayList<>();

        list.add(list1);
        list.add(list2);
        list.add(list3);

        //揭牌
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                Card card = cards.remove(0);
                list.get(j).add(card);
            }
        }
        System.out.println("第一个人 "+ list1);
        System.out.println("第二个人 "+ list2);
        System.out.println("第三个人 "+ list3);

    }
}
